<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <base href="<%=basePath%>"/>
    <title>Index</title>

    <jsp:include page="../header.jsp"></jsp:include>

    <script type="text/javascript">
        $(function () {
            $("#addAttachment").click(function () {
                showAttachmentPanel();
            });

            $('.selectpicker').selectpicker();

            $("#recordPanel").hide();

            $('.selectpicker').change(function(){
                if($(this).val()=='FILE'){
                    $("#filePanel").show();
                }else if($(this).val()=='RECORD'){
                    $("#filePanel").hide();
                }
            });
        });

        function showAttachmentPanel(id, name) {
            $("#attachmentPanel [name='attachment.id']").val(id);
            $("#attachmentPanel [name='attachment.name']").val(name);
            $("#attachmentPanel").modal();
        }
    </script>
</head>
<body>
<jsp:include page="../top.jsp"></jsp:include>

<div class="container theme-showcase" role="main">

    <div class="alert alert-success">
        <h2>档案管理 - <s:property value="project.name"/>  </h2>
    </div>
    <div class="well">
        <div>
            <a class="btn btn-success" id="addAttachment">添加档案</a>
            <a class="btn btn-default" href="project/listProject">返回项目列表</a>
        </div>
    </div>

    <div id="attachmentList">
        <table class="table table-hover">
            <tr>
                <th>档案名称</th>
                <th>类型</th>
                <th>下载</th>
                <th>操作</th>
            </tr>
            <s:iterator value="attachmentList" var="d">
                <tr>
                    <td><s:property value="#d.name"/></td>
                    <td>
                        <s:if test="#d.type.toString() == 'FILE'">
                            文件
                        </s:if>
                        <s:elseif test="#d.type.toString() == 'RECORD'">
                            记录
                        </s:elseif>
                    </td>
                    <td>
                        <s:if test="#d.type.toString() == 'FILE'">
                            <a href="attachment/downloadAttachment?attachment.id=<s:property value='#d.id'/>" class="btn btn-success">下载</a>
                        </s:if>
                    </td>
                    <td>
                        <div class="btn-group" role="group">
                            <button type="button" class="btn btn-primary dropdown-toggle"
                                    data-toggle="dropdown" aria-haspopup="true"
                                    aria-expanded="false">
                                操作 <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li><a
                                        href="attachment/deleteAttachment?attachment.id=<s:property value='#d.id'/>"
                                        onclick="return confirm('确认删除吗？');">删除</a></li>
                            </ul>
                        </div>
                    </td>
                </tr>
            </s:iterator>
        </table>
    </div>
    <div class="modal fade" id="attachmentPanel" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" aria-hidden="true">
        <form action="attachment/saveAttachment" method="post" enctype="multipart/form-data">
            <input type="hidden" name="attachment.id"/>
            <input type="hidden" name="attachment.project.id" value="<s:property value='project.id'/>"/>
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"
                                aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">档案信息</h4>
                    </div>
                    <div class="modal-body">
                        <h4>
                            <ul class="list-group">
                                <li class="list-group-item"><label> 类型 </label>
                                <select name="attachment.type" class="selectpicker">
                                        <option value="FILE" selected="selected">文件</option>
                                        <option value="RECORD">记录</option>
                                    </select>
                                </li>
                                <li class="list-group-item"><label> 档案名 </label> <input
                                        type="text" class="form-control" name="attachment.name"
                                        placeholder="档案名"/></li>
                                <li id="filePanel" class="list-group-item"><label> 文件 </label> <input
                                        type="file" class="form-control" name="file"/></li>
                            </ul>
                        </h4>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-success">保存</button>
                        <button type="button" class="btn btn-default"
                                data-dismiss="modal">取消
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>
